﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using EzFreamWork;
public class SizeChangePanel : MonoBehaviour
{
    //定义变量
    private List<InputField> listInputField = new List<InputField>();//用来管理InputFild的容器
    private Button MaskBtn;
    private Image BG;
    private Image SizeChangeGroup;
    private Toggle Size1;
    private Image Background;
    private Image Checkmark;
    private Toggle Size2;
    private Image Background1;
    private Image Checkmark2;
    private Toggle Size3;
    private Image Background3;
    private Image Checkmark4;
    private Toggle Size4;
    private Image Background5;
    private Image Checkmark6;
    private Toggle Size5;
    private Image Background7;
    private Image Checkmark8;
    private Image SliderGroup;
    private Slider Slider;
    private Image Background9;
    private GameObject FillArea;
    private Image Fill;
    private GameObject HandleSlideArea;
    private Image Handle;
    private void Awake()
    {
        InitFunc();      //获取组件
        AddLisiners();//监听事件
    }
    
    //初始化函数 用于获取UI组件等
    private void InitFunc()
    {
        MaskBtn = ToolUnity.FindGameObject(gameObject, "MaskBtn").GetComponent<Button>();
        BG = ToolUnity.FindGameObject(gameObject, "BG").GetComponent<Image>();
        SizeChangeGroup = ToolUnity.FindGameObject(gameObject, "SizeChangeGroup").GetComponent<Image>();
        Size1 = ToolUnity.FindGameObject(gameObject, "Size1").GetComponent<Toggle>();
        Background = ToolUnity.FindGameObject(gameObject, "Background").GetComponent<Image>();
        Checkmark = ToolUnity.FindGameObject(gameObject, "Checkmark").GetComponent<Image>();
        Size2 = ToolUnity.FindGameObject(gameObject, "Size2").GetComponent<Toggle>();
        Background1 = ToolUnity.FindGameObject(gameObject, "Background1").GetComponent<Image>();
        Checkmark2 = ToolUnity.FindGameObject(gameObject, "Checkmark2").GetComponent<Image>();
        Size3 = ToolUnity.FindGameObject(gameObject, "Size3").GetComponent<Toggle>();
        Background3 = ToolUnity.FindGameObject(gameObject, "Background3").GetComponent<Image>();
        Checkmark4 = ToolUnity.FindGameObject(gameObject, "Checkmark4").GetComponent<Image>();
        Size4 = ToolUnity.FindGameObject(gameObject, "Size4").GetComponent<Toggle>();
        Background5 = ToolUnity.FindGameObject(gameObject, "Background5").GetComponent<Image>();
        Checkmark6 = ToolUnity.FindGameObject(gameObject, "Checkmark6").GetComponent<Image>();
        Size5 = ToolUnity.FindGameObject(gameObject, "Size5").GetComponent<Toggle>();
        Background7 = ToolUnity.FindGameObject(gameObject, "Background7").GetComponent<Image>();
        Checkmark8 = ToolUnity.FindGameObject(gameObject, "Checkmark8").GetComponent<Image>();
        SliderGroup = ToolUnity.FindGameObject(gameObject, "SliderGroup").GetComponent<Image>();
        Slider = ToolUnity.FindGameObject(gameObject, "Slider").GetComponent<Slider>();
        Background9 = ToolUnity.FindGameObject(gameObject, "Background9").GetComponent<Image>();
        FillArea = ToolUnity.FindGameObject(gameObject, "Fill Area").GetComponent<GameObject>();
        Fill = ToolUnity.FindGameObject(gameObject, "Fill").GetComponent<Image>();
        HandleSlideArea = ToolUnity.FindGameObject(gameObject, "Handle Slide Area").GetComponent<GameObject>();
        Handle = ToolUnity.FindGameObject(gameObject, "Handle").GetComponent<Image>();
    }

    private void Start()
    {
        EventCenter.Broadcast<bool>( EventType.CanDraw,false);
        Slider.value = gameObject.GetComponentInParent<Painting>().num;
    }

    private void OnDestroy()
    {
        EventCenter.Broadcast<bool>( EventType.CanDraw, true);
    }

    //将模型层的数据同步到View层
    private void SetData()
    {
    }
    //初始化函数 用于获取UI组件等
    private void AddLisiners()
    {
        MaskBtn.onClick.AddListener(() => {
            Debug.Log("MaskBtn (UnityEngine.GameObject)");
            Destroy(gameObject);
        });
        Size1.onValueChanged.AddListener((e) => {
            Debug.Log("Size1 (UnityEngine.GameObject):" + e);
            EventCenter.Broadcast<float>(EventType.SetSize, 0.3f);
        });
        Size2.onValueChanged.AddListener((e) => {
            Debug.Log("Size2 (UnityEngine.GameObject):" + e);
            EventCenter.Broadcast<float>(EventType.SetSize, 1f);
        });
        Size3.onValueChanged.AddListener((e) => {
            Debug.Log("Size3 (UnityEngine.GameObject):" + e);
            EventCenter.Broadcast<float>(EventType.SetSize, 1.5f);
        });
        Size4.onValueChanged.AddListener((e) => {
            Debug.Log("Size4 (UnityEngine.GameObject):" + e);
            EventCenter.Broadcast<float>(EventType.SetSize, 2f);
        });
        Size5.onValueChanged.AddListener((e) => {
            Debug.Log("Size5 (UnityEngine.GameObject):" + e);
            EventCenter.Broadcast<float>(EventType.SetSize, 4f);
        });
        if (listInputField.Count > 0)
        {
            foreach (InputField item in listInputField)
            {
                item.onValueChanged.AddListener(value => { Debug.Log(item.name + ":" + value); });
            }
        }

        Slider.onValueChanged.AddListener(v => 
        {
            gameObject.GetComponentInParent<Painting>().num = (int)v;
        });
    }
}
